package com.business.etl.flow.listener;

import com.business.etl.flow.service.FlowService;
import com.framework.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * 描述：
 * redis监听事件触发
 * @author xianggj
 * @Date 2021/12/13 13:42
 **/
@Configuration
public class RedisEventConfig {

    @Autowired
    private RedisService redisService;

    @Autowired
    private FlowService flowService;

    @Bean
    public RedisKeyChangeListener redisKeyChangeListener() throws Exception {
        RedisKeyChangeListener listener =
                new RedisKeyChangeListener(redisMessageListenerContainer(), redisService, flowService);
        return listener;
    }


    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer() throws Exception {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        redisService.getRedisTemplate().setEnableTransactionSupport(true);
        container.setConnectionFactory(redisService.getRedisTemplate().getConnectionFactory());
        return container;
    }

}
